﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string conString = "server=.;database=Test;uid=sa;pwd=123456;";
            SqlConnection sqlConnection = new SqlConnection(conString);
            sqlConnection.Open();
            SqlCommand command = new SqlCommand("select * from Students", sqlConnection);
            var reader = command.ExecuteReader();
            Console.WriteLine("{0}\t{1}\t{2}", "学号", "姓名", "年龄");
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}\t{2}", reader["Id"], reader["Name"], reader["Age"]);
            }
            reader.Close();
            //增加
            command.CommandText = "insert into Students(Name,Age)values('曾婷',19)";
            command.ExecuteNonQuery();
            

            //删除
            command.CommandText = "delete from Students where id=1";
            command.ExecuteNonQuery();

            //修改
            command.CommandText = "update Students set Age=3 where Name='曾婷'";
            command.ExecuteNonQuery();

            sqlConnection.Close();
        }
    }
}
